<?php

require_once('configuration/environment/IEnvironmentConfig.class.php');

/**
 * Proxy class for actual IEnvironmentConfig.
 *
 */
class Configuration implements IEnvironmentConfig {
	
	private static $instance;
	
	/**
	 * X.
	 *
	 * @var IEnvironmentConfig
	 */
	private $configuration;
	
	private function __construct() {
		//smoothLog("Creating new Configuration instance. FILE: " . __FILE__);
		$basePathConfigurationMapping = array(
			'/Users/phudy/PhpDev/JsugVotingBackend/' => 'ChristophMacbookEnvironmentConfig',
			'/hoeppsbb/www.hoerspielcrew.at/jsugvoting/backend/' => 'HoerspielcrewEnvironmentConfig',
			'D:\\PhpDev\\JsugVotingBackend\\' => 'BmiWindowsEnvironmentConfiguration'
		);
		
		$className = null;
		$basePath = null;
		foreach($basePathConfigurationMapping as $currentBasePath => $currentConfigClassName) {
			$substrFile = substr(__FILE__, 0, strlen($currentBasePath));
			if($substrFile == $currentBasePath) {
				$className = $currentConfigClassName;
				$basePath = $currentBasePath;
				break;
			}
		}
		
		if($className == null) {
			throw new Exception('No configuration could be found for path [' . __FILE__ . ']!');
		}
		
		$classFullPath = 'configuration/environment/' . $className . '.class.php';
		//smoothLog("Requiring configuration class [$className] by path [$classFullPath].");
		require_once($classFullPath);
		$this->configuration = new $className();
		$this->configuration->__setBasePath($basePath);
		
	}
	
	/**
	 * X.
	 *
	 * @return IEnvironmentConfig
	 */
	public static function getInstance() {
		if(Configuration::$instance == null) {
			Configuration::$instance = new Configuration();
		}
		return Configuration::$instance;
	}
	
	public function __setBasePath($basePath) { throw new Exception('UnsupportedOperation! basePath=[' . $basePath . ']'); }
	public function getLogFileName() { return $this->configuration->getLogFileName(); }
	public function getBasePath() { return $this->configuration->getBasePath(); }
	public function newPdoConnection() { return $this->configuration->newPdoConnection(); }
	public function getLogLevel() { return $this->configuration->getLogLevel(); }
	public function getPdoConfig() { return $this->configuration->getPdoConfig(); }
}

?>